use serde::{Deserialize, Serialize};

use crate::graph::value::Value;

use super::{Input, NodeTrait, Output};

#[derive(Clone, Serialize, Deserialize)]
pub struct ModuleDefNode {
    pub name: String,
    inputs: Vec<Input>,
    outputs: Vec<Output>,
}

impl ModuleDefNode {
    pub fn new(name: String) -> Self {
        Self {
            name,
            inputs: vec![],
            outputs: vec![
                Output {
                    name: "Child".to_string(),
                    description: Some("子节点".to_string()),
                    value: Value::Node
                }
            ],
        }
    }
 }

impl NodeTrait for ModuleDefNode {
    fn name(&self) ->  &str {
        &self.name
    }

    fn ty(&self) ->  &str {
        "__MODULE_NODE__"
    }

    fn description(&self) -> Option<&str> {
        Some("模块节点")
    }

    fn inputs(&self) ->  &[Input] {
        &self.inputs
    }

    fn outputs(&self) ->  &[Output] {
        &self.outputs
    }

    fn has_children(&self) -> bool {
        true
    }

    fn children_count(&self) -> Option<usize> {
        Some(1)
    }

    fn inputs_mut(&mut self) ->  &mut Vec<Input> {
        &mut self.inputs
    }

    fn outputs_mut(&mut self) ->  &mut Vec<Output> {
        &mut self.outputs
    }

    fn can_copy(&self) -> bool {
        false
    }
}

